<template>
	<view class="contont">
		<nav-bar :title="title" :iconLeft="true" />

		<view class="content-bgc">
			<view class="b-con">

				<view style="margin-top: 20rpx;">
					<up-cell-group :border="false">
						<up-cell title="入库单号">
							<template #value>
								<view class="cell-text">{{ detail_record.code }} </view>
							</template>
						</up-cell>
						<up-cell title="委外加工单号">
							<template #value>
								<view class="cell-text">{{ detail_record.machining_code }} </view>
							</template>
						</up-cell>
						<up-cell title="入库日期">
							<template #value>
								<view class="cell-text">{{ detail_record.in_date }}</view>
							</template>
						</up-cell>
						<up-cell title="备注">
							<template #value>
								<view class="cell-text" style="width: 70%;">{{ detail_record.desc }}</view>
							</template>
						</up-cell>
					</up-cell-group>
				</view>
			</view>
			<view class="b-con">
				<up-cell-group :border="false">
					<up-cell :isLink="true" :border="false" :title="`产品：总数量（${car_list.length}）`" @click="car_popupShow = true">
						<template #value>
							<view class="cell-text">点击查看 </view>
						</template>
					</up-cell>
				</up-cell-group>
			</view>
			<custom-popup :popupShow="car_popupShow" mode="bottom" :title="'产品'"
				@close="car_popupShow = false" height="70vh">
				<z-paging v-if="car_popupShow" ref="paging_car" :refresher-enabled="false" :loading-more-enabled="false" :fixed="false" v-model="car_list"
					@query="queryList_car">
					<view class="section_item" v-for="(item, index) in car_list" :key="index">
						<view class="swipe-action">
							<view>名称：{{ item.name }}</view>
							<view class="text-2">编号：{{ item.code }}</view>
							<view class="text-2">规格：{{ item.specification }}</view>
							<view class="con-2">
								<view class="text-2 flex1">基本单位：{{ item.unit_main }}</view>
								<view class="text-2 flex1">加工产品数量：{{ item.num }}</view>
							</view>
							<view class="con-2">
								<view class="text-2 flex1">加工单价(元)：{{ item.machining_price }}</view>
								<view class="text-2 flex1">已入库数量：{{ item.up_num }}</view>
							</view>
							<view class="text-2">入库仓库：{{ item.warehouse_name }}</view>
							<view class="text-2">本期入库数量：{{ item.now_num }}</view>
						</view>
					</view>
				</z-paging>
			</custom-popup>
		</view>
	</view>
</template>
<script setup>
import { reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app'
import enInApi from '../../../api/entrust/en_in'

const detail_record = ref({})
const title = '委外加工入库详情';
onLoad(option => {
	get_warehouse_list(option.id);
})

function get_detail(id, wareList) {
	enInApi.machining_in_detail(id).then(data => {
		detail_record.value = data
		enInApi.get_machining_in_product({ machining_product__machining__id: data.machining }).then(res2 => {
			car_list.value = res2.results.map(v => {
				return {
					id: v.machining_product.product.id,
					machining_product_id: v.machining_product.id,
					code: v.machining_product.product.code,
					name: v.machining_product.product.name,
					specification: v.machining_product.product.specification,
					unit_main: v.machining_product.product.unit_main,
					num: v.num,
					machining_price: v.price,
					up_num: v.up_num,
					now_num: v.now_num,
					warehouse_name: wareList.find(k => k.id == v.warehouse).name
				}
			})
		})
	})
}

const car_popupShow = ref(false)
const car_list = ref([])
const paging_car = ref(null)
function queryList_car() {
	paging_car.value.complete(car_list.value);
}

function get_warehouse_list(optId) {
	const params = { page: 1, page_size: 99999 };
	enInApi.get_warehouse(params).then(res => {
		get_detail(optId, res.results);
	})
}

</script>

<style lang="scss"></style>